
function jiankuSearch()
{
	page_jianku = 1;
	jiankuCondition = $("#jiankuCT").val();
	loadUserLocationInfo_jianku();
}

function loadUserLocationInfo_jianku() {	
    $.ajax({
        type: "get",
        url: "fetchBaseDetailById.action",
        data: { "componentId": 73,  "page": page_jianku, "limit": limit ,"condition":jiankuCondition},
        dataType: "jsonp",
        success: function (datas) {
            if (datas.success == "sessionOut") {
                window.location = "index.html";
                return;
            }
            clearMarker();
            showUserLocationInfo_jianku(datas);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {         
        }
    });
}

function showUserLocationInfo_jianku(data) {
    if (data.success == "true") {
        jiankuResultData = data;
        if (data.totalSize > 0) {
            page_jianku_totle = Math.ceil(data.totalSize / limit);

            if (page_jianku == 1) {
                $("#jkLeft").css("color", "gray");
            } else {
                $("#jkLeft").css("color", "blue");
            }

            if (page_jianku_totle == 1) {
                $("#jkRight").css("color", "gray");
            } else {
                $("#jkRight").css("color", "blue");
            }

            if (page_jianku == page_jianku_totle) {
                $("#jkRight").css("color", "gray");
            }
        }
        if (data.base != undefined && data.base.length != 0) {
            var infoLenth = data.base.length;

            if (infoLenth > 0) {

                var inners = "";
                for (var i = 0; i < infoLenth; i++) {
                    var contents = data.base[i].content.split('||');
                    var name = "";
                    var addr = "";
                    if (contents[0] != undefined && contents[0] != null) {
                        var vn = contents[0].split("|");
                        if (vn[1] != undefined && vn[1] != null) {
                            name = vn[1];
                        }
                    }
                    if (contents[1] != undefined && contents[1] != null) {
                        var va = contents[1].split("|");
                        if (va[1] != undefined && va[1] != null) {
                            addr = va[1];
                        }
                    }       
                    
                    var loc =  data.base[i].location.split(',');   
                              
                    inners += " <div id='listarea'>";
                    inners += "<div id='listareaLeft'><img src='images/pic_temp.png' width='40' height='40' /></div>";
                    inners += "<div id='listareaRight'>";
                    inners += "<div id='topcontent'>";
                   // if(loc.length==2){
                        var lat = loc[0];
                        var lon = loc[1];
                        inners += "<div id='name'><a href='javascript:detailInfo_jianku("+data.base[i].id+","+lat+","+lon+")'>" + name + "</a></div>";
                   // }
                   // else
                    //    inners += "<div id='name'>" + name + "</div>";
                    inners += "<div id='time'><img src='images/time_ico.gif' width='18' height='18' class='ico' />" + data.base[i].formatDate + "</div>";
                    inners += "</div>";
                    inners += "<div id='bottomcontent'>";
                    inners += "<div id='jianku_address'>" + addr + "</div>";
                    inners += "<div id='jianku2ndBtnArea'><a  href='javascript:void(0)' onclick='circlePage(" + data.base[i].id+","+lat+","+lon+")' >生活圈调查</a> | <a href='wuyeJiankuIndex.action?componentId=74&parentId= " + data.base[i].id + "' target='_blank'>详细信息</a></div>";
                    inners += "</div>";
                    inners += " </div>  ";
                    inners += " </div>  ";
                  
                    if(loc.length==2)
                    {
                        var lat = loc[0];
                        var lon = loc[1];
                        if (lat != null && lon != null && positionInChina(lat, lon)) {

                            var point = new BMap.Point(lon, lat);    // 创建点坐标
                            if (i == 0) {
                                map.centerAndZoom(point, 13);                     // 初始化地图,设置中心点坐标和地图级别。
                            }
                            pintterArr.push(point);
                            addMarker_jianku(point, i, data.base[i]);
                        }
                    }
                }
                if (pintterArr != null && pintterArr.length > 0)
                    map.setViewport(pintterArr);
                $("#Shortlist_jiankuContent").html(inners);
            }
        }
        else {
            $("#Shortlist_jiankuContent").html("");
        }
    }
}

function circlePage(id,lat,lon)
{
    detailInfo_jianku(id,lat,lon);
	path = "fetchlivingCircleByParentId.action?parentId = " + id;
	window.open(path);
}

function detailInfo_jianku(wid,lat,lon){
	 if (lat != null && lon != null && positionInChina(lat, lon)) {                             
          var point = new BMap.Point(lon, lat);   
          
		 var infoLenth = jiankuResultData.base.length;
	      if (infoLenth > 0) {   
	       for (var i = 0; i < infoLenth; i++) {  
				if(jiankuResultData.base[i].id==wid)
				{
					 var obj=jiankuResultData.base[i];
					 var contents = obj.content.split('||');
                     var name = "";
                     var addr = "";

                     if (contents[0] != undefined && contents[0] != null) {
                        var vn = contents[0].split("|");
                        if (vn[1] != undefined && vn[1] != null) {
                            name = vn[1];
                           }
                      }
                      if (contents[1] != undefined && contents[1] != null) {
                          var va = contents[1].split("|");
                          if (va[1] != undefined && va[1] != null) {
                            addr = va[1];
                            }
                     }
				 
			        var htmlText = '       <div id="popup_kuang2">';   		         
	                htmlText += '       <div id="popup_con">';   
                    htmlText += '               <ul>';
		            htmlText += '                   <li><strong>名称</strong>：' + name + '</li>';
	                htmlText += '                   <li><strong>地址</strong>：' + addr + '</li>';
                    htmlText += '               </ul>';
		            htmlText += '           </div>';
                    htmlText += '       </div>';
                    var opts = {
			                        width: 200,     // 信息窗口宽度  
			                        height: 40,     // 信息窗口高度  
			                        //title: "<b>"+obj.name+"</b>"  // 信息窗口标题  
			                    }
			
	                var infoWindow = new BMap.InfoWindow(htmlText, opts);  // 创建信息窗口对象  
		            map.openInfoWindow(infoWindow, point);      // 打开信息窗口   
       
				}
			}	
		}       
               
           map.centerAndZoom(point, 15);
           $("#circleJiankuPoint").val(lat + "," + lon);    
           $("#circleParenetID").val(wid);      
                         
       }      
	}

function addMarker_jianku(point, index, obj) {
    var img = "images/point_jianku.png";

    // 创建图标对象  
	var myIcon = new BMap.Icon(img, new BMap.Size(46, 46),{  	
	   offset: new BMap.Size(10, 25),  	  
	 });
	 // 创建标注对象并添加到地图  
	 var marker = new BMap.Marker(point, {icon: myIcon});
     var contents = obj.content.split('||');
     var name = "";
     var addr = "";

     if (contents[0] != undefined && contents[0] != null) {
        var vn = contents[0].split("|");
        if (vn[1] != undefined && vn[1] != null) {
            name = vn[1];
           }
      }
      if (contents[1] != undefined && contents[1] != null) {
          var va = contents[1].split("|");
          if (va[1] != undefined && va[1] != null) {
            addr = va[1];
            }
        }   
        var htmlText = '       <div id="popup_kuang2">';   		         
	    htmlText += '       <div id="popup_con">';   
        htmlText += '               <ul>';
		htmlText += '                   <li><strong>名称</strong>：' + name + '</li>';
	    htmlText += '                   <li><strong>地址</strong>：' + addr + '</li>';
        htmlText += '               </ul>';
		htmlText += '           </div>';
        htmlText += '       </div>';
        var opts = {
			            width: 200,     // 信息窗口宽度  
			            height: 40,     // 信息窗口高度  
			            //title: "<b>"+obj.name+"</b>"  // 信息窗口标题  
			        }
			
		var infoWindow = new BMap.InfoWindow(htmlText, opts);  // 创建信息窗口对象  
			      
        marker.addEventListener("mouseover", function(){
        this.openInfoWindow(infoWindow);
        });
        marker.addEventListener("mouseout", function(){
        this.closeInfoWindow();
        });
        
    map.addOverlay(marker);
}

function clearCircleINFO()
{
	$("#circleName").val("");
	$("#circleTransportWay").val("");
	$("#circleStationNum").val("");
	$("#circleSingletripTime").val("");
	$("#circleAreaDistance").val("");
	$("#circlePeakCongestion").val("");
	$("#circleConstruction").val("");
	$("#circleCompanyType").val("");
	$("#circleStationDistance").val("");
}

function circleRefresh()
{
	clearCircleINFO();
	mapCircleChoose();
}

function circleAdd()
{
	
	var lcName = $("#circleName").val();
	var transportWay = $("#circleTransportWay").val();
	var stationNum = $("#circleStationNum").val();
	var singletripTime = $("#circleSingletripTime").val();
	var areaDistance = $("#circleAreaDistance").val();
	var peakCongestion = $("#circlePeakCongestion").val();
	var construction = $("#circleConstruction").val();
	var companyType = $("#circleCompanyType").val();
	var stationDistance = $("#circleStationDistance").val();
	var lcRadius = $("#circleDistance").val();
	var lcLocation = $("#circlePoints").val();
	var parentID = $("#circleParenetID").val();
	if(lcLocation=="")
	{
		alert("请单击地图按钮，在地图上选择一点作为商圈的中心点！"); 			
 		return false;	
	}
	if(lcName==""){
		alert("请输入名称"); 			
 		return false;	
	}
	else if(inputTxt(lcName)){				
		return false;		
	}
	if(transportWay==""){
		alert("请输入交通方式"); 			
 		return false;	
	}
	else if(inputTxt(transportWay)){				
		return false;		
	}

	 if(stationNum!=""&&stationNum!="0"&&!r.test(stationNum)){
 		alert("站数必须是整数。"); 			
 		return false;	
   	}
	if(singletripTime==""){
		alert("请输入单程时间"); 			
 		return false;	
	}
	else if(singletripTime!=""&&!r.test(singletripTime)){
 		alert("单程时间必须是整数。"); 			
 		return false;	
   	}
	if(areaDistance==""){
		alert("请输入项目与商圈距离"); 			
 		return false;	
	}
	else if(areaDistance!=""&&isNaN(areaDistance)){
		alert("项目与商圈距离必须是数字。");	
		return false;
	}	
	if(peakCongestion==""){
		alert("请输入高峰拥挤情况"); 			
 		return false;	
	}
	else if(inputTxt(peakCongestion)){				
		return false;		
	}
	if(construction==""){
		alert("请输入目标人群集中的代表建筑"); 			
 		return false;	
	}
	else if(inputTxt(construction)){				
		return false;		
	}
	if(companyType==""){
		alert("请输入入住公司类型"); 			
 		return false;	
	}
	else if(inputTxt(companyType)){				
		return false;		
	}
	 if(stationDistance!=""&&stationDistance!="0.0"&&isNaN(stationDistance)){
		alert("项目距站点步行距离距离必须是数字。");	
		return false;	
	}
	
	 $.ajax({
        type: "get",
        url: "addlivingCircle.action",
        data: { "lcName": lcName,"transportWay": transportWay,"stationNum": stationNum,"singletripTime": singletripTime,"areaDistance": areaDistance,"peakCongestion": peakCongestion,"construction": construction,"companyType": companyType,"stationDistance": stationDistance,"parentId": parentID,"lcLocation":lcLocation,"lcRadius":lcRadius},
        dataType: "jsonp",
        success: function (datas) {            
            if (datas.success == "true")
				{					
					alert("新增成功！");
					clearCircleINFO();
					closeCircle();
					//var path = "fetchlivingCircleByParentId.action?parentId = " + parentID;
					//window.open(path);
				}
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {  
			
        }
    });
}

function confirmationInfo()
{
	var lcName = $("#circleName").val();
	var transportWay = $("#circleTransportWay").val();
	var stationNum = $("#circleStationNum").val();
	var singletripTime = $("#circleSingletripTime").val();
	var areaDistance = $("#circleAreaDistance").val();
	var peakCongestion = $("#circlePeakCongestion").val();
	var construction = $("#circleConstruction").val();
	var companyType = $("#circleCompanyType").val();
	var stationDistance = $("#circleStationDistance").val();
	
	
	if(lcName==""){
		alert("请输入名称"); 			
 		return false;	
	}
	else if(inputTxt(lcName)){				
		return false;		
	}
	if(transportWay==""){
		alert("请输入交通方式"); 			
 		return false;	
	}
	else if(inputTxt(transportWay)){				
		return false;		
	}

	if(stationNum==""){
		alert("请输入站数"); 			
 		return false;	
	}
	else if(stationNum!=""&&!r.test(stationNum)){
 		alert("站数必须是整数。"); 			
 		return false;	
   	}
	if(singletripTime==""){
		alert("请输入单程时间"); 			
 		return false;	
	}
	else if(singletripTime!=""&&!r.test(singletripTime)){
 		alert("单程时间必须是整数。"); 			
 		return false;	
   	}
	if(areaDistance==""){
		alert("请输入项目到商圈距离"); 			
 		return false;	
	}
	else if(inputTxt(areaDistance)){				
		return false;		
	}	
	if(peakCongestion==""){
		alert("请输入高峰拥挤情况"); 			
 		return false;	
	}
	else if(inputTxt(peakCongestion)){				
		return false;		
	}
	if(construction==""){
		alert("请输入目标人群集中的代表建筑"); 			
 		return false;	
	}
	else if(inputTxt(construction)){				
		return false;		
	}
	if(companyType==""){
		alert("请输入入住公司类型"); 			
 		return false;	
	}
	else if(inputTxt(companyType)){				
		return false;		
	}
	if(stationDistance==""){
		alert("请输入项目距站点步行距离距离"); 			
 		return false;	
	}
	else if(stationDistance!=""&&isNaN(stationDistance)){
		alert("项目距站点步行距离距离必须是数字。");	
		return false;	
	}
}

function previousPage_jianku() {
    if (page_jianku == 1) {        
        return false;
    }
    map.clearOverlays();
    pintterArr = new Array();
    page_jianku = page_jianku - 1;
    if (page_jianku == 1) {
        $("#jkLeft").css("color", "gray");
    }
    $("#jkRight").css("color", "blue");
    loadUserLocationInfo_jianku();
}

function nextPage_jianku() {
    if (page_jianku == page_jianku_totle) {       
        return false;
    }
    map.clearOverlays();
    pintterArr = new Array();
    page_jianku = page_jianku + 1;
    if (page_jianku == page_jianku_totle) {
        $("#jkRight").css("color", "gray");
    }
    $("#jkLeft").css("color", "blue");
    loadUserLocationInfo_jianku();
}